package cn.htsyb.synergy.security.web.services;

import cn.htsyb.synergy.security.web.dao.SecurityAuthMetaDao;
import cn.htsyb.synergy.security.web.model.SecurityUserDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * @author lakeside hubin_yuan.410@hotmail.com
 * @version V1.0.0
 * @date 2022/5/22
 * @since 1.0
 */
@Service
@Slf4j
public class SecurityUserService implements UserDetailsService {

    @Resource
    private SecurityAuthMetaDao authMetaDao;

    @Override
    public UserDetails loadUserByUsername(String loginName) throws UsernameNotFoundException {

        SecurityUserDetail userDetail = authMetaDao.findUserDetailByUsername(loginName);
        userDetail.setAuthorities(authMetaDao.findAuthorityByAccountId(userDetail.getId()));
        return userDetail;
    }


}
